package com.vote.common.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * 投票类型枚举
 */
public enum VoteTypeEnum {

    ANONYMOUS(0, "匿名投票", "color: #008000"),
    REAL_NAME(1, "实名投票", "color: #f04b09");

    private Integer code;

    private String type;

    private String color;

    VoteTypeEnum (Integer code, String type, String color) {
        this.code = code;
        this.type = type;
        this.color = color;
    }

    public Integer getCode() {
        return code;
    }

    public String getType() {
        return type;
    }

    public String getColor() {
        return color;
    }

    public static VoteTypeEnum getInstance(Integer code) {
        for (VoteTypeEnum item : VoteTypeEnum.values()) {
            if (code.equals(item.getCode())) {
                return item;
            }
        }
        return null;
    }

    public static VoteTypeEnum getByDesc(String desc) {
        for (VoteTypeEnum item : VoteTypeEnum.values()) {
            if (StringUtils.equals(desc, item.getType())) {
                return item;
            }
        }
        return null;
    }
}
